﻿using ARchGL.Platform.FileServer;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
using WebApiClient;

namespace ARchGL.Platform.Mpp
{
    /// <summary>
    /// SpiderBim文件服务 接口
    /// </summary>
    public static class MppHttpsModule
    {
        public static IServiceCollection Register(IServiceCollection services, IConfigurationRoot appConfiguration)
        {
            services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();

            void config(HttpApiConfig c)
            {
                c.HttpHost = new Uri(appConfiguration["App:ServerRootAddress"]);
                c.GlobalFilters.Add(new DefaultHeaderAttribute(appConfiguration));
                //c.GlobalFilters.Add(new ServiceTokenAttribute());
            }
            services.AddHttpApi<IMppProjectApi>().ConfigureHttpApiConfig(config); //注入Mpp项目进度
            return services;
        }

        ///// <summary>
        ///// 添加HttpApi
        ///// 返回HttpApi工厂
        ///// </summary>
        ///// <typeparam name="TInterface">接口类型</typeparam>
        ///// <param name="services"></param>
        ///// <returns></returns>
        //public static HttpApiFactoryBuilder<TInterface> AddHttpApi<TInterface>(this IServiceCollection services)
        //    where TInterface : class, IHttpApi
        //{
        //    return new HttpApiFactoryBuilder<TInterface>(services);
        //}
    }
}
